import { createRouter, createWebHistory } from "vue-router";
import { get } from "../util/localStorage";
import axios from "axios";

import Login from "../views/login/login.vue";
import Register from "../views/register/register.vue";
import Index from "../views/index/index.vue";
import User from "../views/user/user.vue";
import Statistics from "../views/statistics/statistics.vue";
import Permission from "../views/permission/permission.vue";
import Equipment from "../views/equipment/equipment.vue";
import Dispatch from "../views/dispatch/dispatch.vue";

const routes = [
  {
    path: "/",
    component: Login,
  },
  {
    path: "/register",
    component: Register,
  },
  {
    path: "/index",
    component: Index,
    children: [
      {
        path: "dispatch",
        component: Dispatch,
      },
      {
        path: "statistics",
        component: Statistics,
      },
      {
        path: "user",
        component: User,
      },
      {
        path: "permission",
        component: Permission,
      },
      {
        path: "equipment",
        component: Equipment,
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to) => {
  const user = get("user");
  console.log(to);

  if (to.path !== "/" && user) {
    // return;
  }

  if (!user && to.path !== "/") {
  }
});

export default router;
